package com.lzs.kunei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzs.entity.Move;

import com.lzs.kunei.mapper.MoveMapper;
import com.lzs.kunei.service.MoveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzs.util.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wpy
 * @since 2020-11-24
 */
@Service
public class MoveServiceImpl extends ServiceImpl<MoveMapper, Move> implements MoveService {
    @Autowired
    private MoveMapper moveMapper;
    @Override
    public Page<Move> selectMovePage(Integer current, Integer size, Move move,String[] warehouseid) {
        Page<Move> movePage=new Page<>(current,size);
        Long commodityid = move.getCommodityid();
        String commodityname = move.getCommodityname();
        String locatorcode = move.getLocatorcode();
        String locatorname = move.getLocatorname();
        String state = move.getState();
        QueryWrapper<Move> queryWrapper=new QueryWrapper<>();
        queryWrapper.in("warehouseid",warehouseid);
        if (commodityid!=null&&commodityid.toString()!=""){
            queryWrapper.like("commoditybar",commodityid);
        }
        if (StringUtils.isNotEmpty(commodityname)){
            queryWrapper.like("commodityname",commodityname);
        }
        if (StringUtils.isNotEmpty(locatorcode)){
            queryWrapper.like("locatorcode",locatorcode);
        }
        if (StringUtils.isNotEmpty(locatorname)){
            queryWrapper.like("locatorname",locatorname);
        }
        if (StringUtils.isNotEmpty(state)){
            queryWrapper.like("state",state);
        }
        moveMapper.selectPage(movePage,queryWrapper);
        return movePage;
    }


    @Override
    public R updateAudit(String state, List<Long> list) {
        int i=-1;
        if (list!=null&&list.size()>0){
            i = moveMapper.updateAudit(state, list);
        }
        if (i!=-1){
            return R.ok().message("操作成功");
        }else {
            return R.error().message("操作成功");
        }
    }
}
